package org.example.hadoop.service.authorSort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.example.hadoop.domain.AuthorCountBean;

import java.io.IOException;

/**
 * @Author: wwy
 * @Date: 2020/11/10 11:44
 */
public class AuthorSortReducer extends Reducer<AuthorCountBean, Text, Text, IntWritable> {
    /**
     * k2               v2
     * authorCountBean  余华，aa,bbb,ccc,ddd
     *
     * k3               v3
     * 余华              138
     * aa                137
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(AuthorCountBean key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        for (Text value : values) {
            context.write(value,new IntWritable(key.getCount()));
        }

    }
}
